<template>
  <div
    class="login-wrap"
    :style="`background: url('${loginBg}') center center no-repeat`"
  >
    <div
      class="login-content"
      :style="`background: url('${loginFormBg}') center center no-repeat`"
    >
      <div class="head">
        <h3 class="title">登录页</h3>
        <p class="greet">欢迎来到平台管理中心</p>
      </div>
      <el-form
        class="login-form-wrap"
        :model="form"
        :rules="rules"
        ref="formVm"
      >
        <el-form-item prop="username">
          <el-input placeholder="请输入用户名" v-model="form.username">
            <template #prefix>
              <el-icon><user /></el-icon>
            </template>
          </el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            :type="passInputType"
            placeholder="请输入密码"
            v-model="form.password"
          >
            <template #prefix>
              <el-icon><lock /></el-icon>
            </template>
            <template #suffix>
              <el-icon
                ><View
                  class="view-icon"
                  :class="{ 'is-active': passVisible }"
                  @click="passVisibleTaggleClick"
              /></el-icon>
            </template>
          </el-input>
        </el-form-item>
        <el-form-item prop="code">
          <el-input placeholder="请输入验证码" v-model="form.code">
            <template #prefix>
              <el-icon><folder-checked /></el-icon>
              <!-- <el-icon><document-checked /></el-icon> -->
            </template>
          </el-input>
          <Identify class="identify"></Identify>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            :loading="loading"
            class="login-btn"
            @click="submitForm"
            >登录</el-button
          >
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

identifyCode

<script>
const loginBg = require('@/assets/images/login-bg.jpg')
const loginFormBg = require('@/assets/images/login-form-bg.png')
import { User, Lock, FolderChecked, View } from '@element-plus/icons'
import { Identify } from '@/components'
import { computed, reactive, ref } from 'vue'
import { useStore } from 'vuex'
import { useRouter } from 'vue-router'
import { login } from '../../api/login'
export default {
  name: 'Login',
  components: {
    User,
    Lock,
    FolderChecked,
    View,
    Identify
  },
  setup() {
    const store = useStore()
    const router = useRouter()
    const passVisible = ref(false)
    const formVm = ref()
    const loading = ref(false)
    const form = reactive({
      username: '',
      password: '',
      code: ''
    })
    const rules = reactive({
      username: {
        required: true,
        message: '用户名不能为空',
        trigger: 'blur'
      },
      password: {
        required: true,
        message: '密码不能为空',
        trigger: 'blur'
      },
      code: {
        required: true,
        message: '验证码不能为空',
        trigger: 'blur'
      }
    })
    const passInputType = computed(() =>
      passVisible.value ? 'text' : 'password'
    )

    // 密码查看切换
    const passVisibleTaggleClick = () => {
      passVisible.value = !passVisible.value
    }

    const submitForm = () => {
      formVm.value.validate((valid) => {
        // console.log('submitForm', valid)
        if (!valid) return
        loading.value = true
        store
          .dispatch('user/login', form.value)
          .then(() => {
            loading.value = false
            router.push({ path: '/' })
          })
          .catch(() => {
            loading.value = false
          })
      })
      login({
        isNeedToken: false,
        isRetry: false,
        loadingCallback(value) {
          console.log(123123, value)
        }
      })
    }

    return {
      loginBg,
      loginFormBg,
      passVisible,
      passInputType,
      formVm,
      form,
      rules,
      loading,
      passVisibleTaggleClick,
      submitForm
    }
  }
}
</script>

<style lang="scss" scoped>
.login-wrap {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  background-size: cover;
}
.login-content {
  width: 456px;
  height: 560px;
  box-sizing: border-box;
  padding: 40px 50px;
  background-size: cover;
  position: absolute;
  right: 150px;
  top: 50%;
  transform: translateY(-50%);
  .head {
    .title {
      font-size: 54px;
      font-weight: 500;
      color: var(--el-color-white);
    }
    .greet {
      margin-top: 29px;
      margin-bottom: 29px;
      font-size: 26px;
      font-weight: 400;
      color: var(--el-color-white);
    }
  }
}
</style>

<style lang="scss">
// 充值表单样式
.login-form-wrap {
  position: relative;
  z-index: 111;
  $height: 48px;
  .el-input {
    .el-input__inner {
      height: $height !important;
      line-height: $height !important;
      outline: none !important;
    }
    .el-input__suffix {
      right: 10px !important;
    }
    .el-icon {
      line-height: $height;
      // font-size: 0;
      svg {
        font-size: 18px;
        vertical-align: middle;
      }
      .view-icon {
        cursor: pointer;
        &.is-active {
          color: var(--el-color-primary);
        }
      }
    }
  }

  .identify {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
  }

  .login-btn {
    width: 100%;
    display: block;
    min-height: $height !important;
  }
}
</style>
